package com.learn.sunday.auth.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Data
@JsonRootName("ResponseStatusObject")
public class ResponseStatus {

    @JsonProperty("RequestURL")
    private String requestUrl;
    @JsonProperty("StatusCode")
    private int statusCode;
    @JsonProperty("StatusString")
    private String statusString;
    @JsonProperty("Id")
    private String id;
    @JsonProperty("LocalTime")
    private Date localTime;

    public static ResponseStatus successResponse(HttpServletRequest request){
        ResponseStatus statusResponse = new ResponseStatus();
        statusResponse.setStatusCode(0);
        statusResponse.setRequestUrl(request.getRequestURI());
        statusResponse.setLocalTime(new Date());
        statusResponse.setStatusString("successful");
        return statusResponse;
    }

    public static ResponseStatus failedResponse(HttpServletRequest request){
        ResponseStatus responseStatus = successResponse(request);
        responseStatus.setStatusCode(1);
        return responseStatus;
    }

    public ResponseStatus setId(String id) {
        this.id = id;
        return this;
    }

    public ResponseStatus setStatusString(String statusString) {
        this.statusString = statusString;
        return this;
    }
}
